package it.fuzzylogics.fuzzywidgetsLibrary.client.FuzzyListeners;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.Element;


public class FMouseUpListener {
    public FMouseUpListener(Element e, FMouseUpHandler handler) {
        attachMouseUpHandler(e, handler);
    }


    public static void setMouseUpEvent(Element e, FMouseUpHandler handler) {
        new FMouseUpListener(e, handler);
    }

    private static native void dispatchMouseUpHendler(JavaScriptObject event, FMouseUpHandler handler) /*-{

    if (!event) event = $wnd.event;
           var x = event.clientX;
            var y = event.clientY;

            handler.@it.fuzzylogics.fuzzywidgetsLibrary.client.FuzzyListeners.FMouseUpHandler::onMouseUp(II)(x,y);

          if (event.preventDefault)
                     event.preventDefault();
                 event.returnValue = false;

      }-*/;

    private native void attachMouseUpHandler(Element e, FMouseUpHandler handler) /*-{

         e.onmouseup = handler;

               if ($wnd.addEventListener && !$wnd.opera) {
                   e.addEventListener('onmouseup', @it.fuzzylogics.fuzzywidgetsLibrary.client.FuzzyListeners.FMouseUpListener::dispatchMouseUpHendler(Lcom/google/gwt/core/client/JavaScriptObject;Lit/fuzzylogics/fuzzywidgetsLibrary/client/FuzzyListeners/FMouseUpHandler;), false);
               }

          e.onmouseup = function(event) {

                   @it.fuzzylogics.fuzzywidgetsLibrary.client.FuzzyListeners.FMouseUpListener::dispatchMouseUpHendler(Lcom/google/gwt/core/client/JavaScriptObject;Lit/fuzzylogics/fuzzywidgetsLibrary/client/FuzzyListeners/FMouseUpHandler;)(event,handler);

          }

      }-*/;
}
